$(function(){
	historyList();
	function historyList(){
		var archivesId= utilModule.getQueryString("archivesId");
		var param="archivesId="+archivesId;
		function callBack(data){
			console.log(data);
			if(data.result==""){
				$(".medicalHistory-no").show();
				$(".mui-table-view").hide();
				$(".medicalHistory-bot").hide();
				$(".history-prompt").hide();
			}else{
				$(".medicalHistory-no").hide();
				$(".mui-table-view").show();
				$(".medicalHistory-bot").show();
				$(".history-prompt").show();
				var html="";
				for(i in data){
					html+='<li class="mui-table-view-cell" anid="'+data[i].id+'">'
								+'<div class="mui-slider-right mui-disabled">'
									+'<a class="mui-btn mui-btn-grey">编辑</a>'
									+'<a class="mui-btn mui-btn-red">删除</a></div>'
								+'<div class="mui-slider-handle">'
										+'<div class="name">诊断记录：'+data[i].diagnosticRecord
											+'<span>'+data[i].diagnosticDate+'</span></div>'
										+'<div class="info">'
											+'医生姓名：<span>'+data[i].doctorName+'</span>'
											+'<p>诊断日期：<span>'+data[i].createTime+'</span></p>'
										+'</div></div></li>';
				}
				$(".mui-table-view").append(html);
				
				$(".mui-btn-grey").on("click",function(event){
					event.stopPropagation();
					var id=$(this).parent().parent().attr("anid");
					location.href="history-add.html?archivesId="+archivesId+"&id="+id;
				});
				
				var btnArray = ['确认', '取消'];
				$(".mui-btn-red").on("click",function(event){
					event.stopPropagation();
					var id=$(this).parent().parent().attr("anid");
					mui.confirm('确认删除该条记录？', '提示', btnArray, function(e) {
						if (e.index == 0) {
							var json="pdId="+id;
							function back(info){
								console.log(info);
								if(info==1){
									mui.toast("删除成功");
									location.reload();
								}else{
									mui.toast("删除失败");
									location.reload();
								}
							}
							electronicArchivesMdule.deletepage(json,back);
						} else {
							location.reload();
						}
					});
				});
				
			}
		}
		electronicArchivesMdule.listpage(param,callBack);
	}
	$(".medicalHistory-bot button").on("click",function(){
		var archivesId= utilModule.getQueryString("archivesId");
		location.href="history-add.html?archivesId="+archivesId;
	});
	$(".medicalHistory-no button").on("click",function(){
		var archivesId= utilModule.getQueryString("archivesId");
		location.href="history-add.html?archivesId="+archivesId;
	});
	
	$(".mui-table-view li").on("click",function(){
		var anid= $(this).attr("anid");
		location.href="history-detail.html?pdId="+anid;
	});
})
